import 'package:flutter/services.dart';

/// 自定义限制最大数值
class MaxValueTextFormatter extends TextInputFormatter {
  MaxValueTextFormatter({this.maxValue = 100});

  final int maxValue;

  @override
  TextEditingValue formatEditUpdate(
      TextEditingValue oldValue, TextEditingValue newValue) {
    int newIntValue = int.tryParse(newValue.text) ?? 0;
    if (newIntValue > maxValue) {
      return oldValue; // Reject the new value
    }
    return newValue; // Accept the new value
  }
}
